'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Public Class ContactWindowViewModelService
    Inherits IcqInterface.ContextService
    Implements IContactWindowViewModelService

    Private _Windows As New Dictionary(Of ContactViewModel, MessageWindow)

    Public Sub New(ByVal context As IcqInterface.Interfaces.IContext)
        MyBase.New(context)
    End Sub

    Public Function GetMessageWindowViewModel(ByVal contact As ViewModel.ContactViewModel) As ViewModel.MessageWindowViewModel Implements ViewModel.IContactWindowViewModelService.GetMessageWindowViewModel
        SyncLock _Windows
            If Not _Windows.ContainsKey(contact) Then
                _Windows.Add(contact, New MessageWindow(contact))
            End If

            Return _Windows(contact).ViewModel
        End SyncLock
    End Function

    Public Function IsMessageWindowViewModelAvailable(ByVal contact As ViewModel.ContactViewModel) As Boolean Implements ViewModel.IContactWindowViewModelService.IsMessageWindowViewModelAvailable
        SyncLock _Windows
            Return _Windows.ContainsKey(contact)
        End SyncLock
    End Function

    Public Sub RemoveMessageWindowViewModel(ByVal contact As ViewModel.ContactViewModel) Implements ViewModel.IContactWindowViewModelService.RemoveMessageWindowViewModel
        SyncLock _Windows
            _Windows.Remove(contact)
        End SyncLock
    End Sub
End Class